<?php

require_once 'actions/login.cls.php';
require_once 'actions/signup.cls.php';
require_once 'actions/request_password_reset.cls.php';
require_once 'ActionFramework/form.cls.php';
require_once 'ActionFramework/formcomponents/password.php';
	
?>

<div id="login">

	<div id="login-tabs">
		<?php
		$choice = str_endswith($_SERVER["REQUEST_URI"], '#login') ? 'signup' : 'login';
		?>
		
		<script type="text/javascript">
			current = 'login';

			function login_or_signup(what) {
				if (what == current) {
					return
				}
				else {
					current = what;
				}
				$("#login-tab").toggleClass('active-login-tab');
				$("#signup-tab").toggleClass('active-login-tab');
				$("#login-tab-page").toggleClass('active-login-page');
				$("#signup-tab-page").toggleClass('active-login-page');
			}

			$(function () { login_or_signup('<?php echo $choice; ?>') });
		</script>
		<a id="login-tab" href="javascript:login_or_signup('login')" class="active-login-tab">login</a>
		<a id="signup-tab" href="javascript:login_or_signup('signup')">register</a>
	</div>
	
	<div id="login-pages">
	
		<div id="login-tab-page" class="login-page active-login-page">
			<?php 
			
				// This is for password reset
				
				$action_reset = new RequestPasswordResetAction();
				$reset_form = $action_reset->get_form_link();
				echo $reset_form->start();
				$email_for_reset = $reset_form->generate(new HiddenField(RequestPasswordResetAction::INPUT_EMAIL));
				echo $email_for_reset;
				echo $reset_form->end();
			
				
				// This is the actual login
			
				$action_login = new LoginAction();
				$form = $action_login->get_form_link();
				
				echo $form->start();
				
				$email = $form->generate(new TextField(LoginAction::INPUT_EMAIL));
				$password = $form->generate(new PasswordComponent($claim_password=LoginAction::INPUT_PASSWORD,
												  $challenge = $view->challenge ));
				
				$email->set_initial_value('your email');
				$password->set_initial_value('your password');
				
				echo "<div class='login_textbox_1'>
						{$email->__toString()}
					  </div>
					  ";
				echo "<div class='login_textbox_2'>
						{$password->__toString()}
					  </div>
					  ";

				echo "<script type='text/javascript'>";
				foreach (array($email, $password) as $item) {
					echo "
						$('#{$item->get_id()}').focus(function () {
							if ($(this).val() == '{$item->get_initial_value()}') {
								$(this).val('');
							}
						});
					";
				}
				echo "</script>";						
						
				echo $form->generate(new HiddenField(LoginAction::INPUT_CHALLENGE_ID, $value=$view->challenge_id));
				
				echo $form->generate_submit('login');
				$getter = $email->get_js_getter();
				$setter = $email_for_reset->get_js_setter();
				$submitter = $reset_form->get_js_submitter();
				echo "<a href='#' onclick=\"$setter($getter()); $submitter(); return false;\">Forgot password</a>";
				
				echo $form->end();
			?>
		</div>
		
		<div id="signup-tab-page" class="login-page">
			<?php 
				$action_signup = new SignupAction();
				$form = $action_signup->get_form_link(); 
				
				echo $form->start();

				// Bind components to form inputs
				$name = $form->generate(new TextField($claim=SignupAction::INPUT_NAME));
				$email = $form->generate(new TextField($claim=SignupAction::INPUT_EMAIL));
				
				$name->set_initial_value('your first name');
				$email->set_initial_value('your email');
				
				echo "<div class='login_textbox_1'>
						{$name->__toString()}
					  </div>
					  ";
				echo "<div class='login_textbox_2'>
						{$email->__toString()}
					  </div>
					  ";
				
				echo "<script type='text/javascript'>";
				foreach (array($name, $email) as $item) {
					echo "
						$('#{$item->get_id()}').focus(function () {
							if ($(this).val() == '{$item->get_initial_value()}') {
								$(this).val('');
							}
						});
					";
				}
				echo "</script>";
				
				echo $form->generate_submit('join!');
				echo $form->end();
			?>
		</div>
		
	</div>
	
</div>
			
<div>

	<div>
		The Tandem Delft project is based on the idea that the best way to learn a language, is 
		to <a href="http://www.youtube.com/watch?v=_yhnWnR1g7M" rel="prettyPhoto" title="TEDx talk Benny Lewis: Language hacking">
		practise it</a>. In this poject we want to provide a platform for students and other interested 
		people within Delft; to meet with native speakers from all around to put their knowledge into 
		practise; improve their skills and in return teach someone else your own native language. 
	</div>
	
	<div id='mini-logos'>
		<div id="mini-logo-tudelft">
			<a href="http://www.tudelft.nl">
				<img src="static/img/logo_TUDelft.png">
			</a>
		</div>
		<div id="mini-logo-aegee">
			<a href="http://www.aegee-delft.nl">
				<img src="static/img/logo_AEGEE.png">
			</a>
		</div>
		<div id="mini-logo-diss">
			<a href="http://www.diss-online.nl/">
				<img src="static/img/logo_DISS.png">
			</a>
		</div>
	</div>
</div>		